<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="选择上级领导">
          <j-select-user-by-dep :multi="false" placeholder="请选择上级审批领导" v-decorator="['superiorUserName', validatorRules.superiorUserName]" :trigger-change="true"></j-select-user-by-dep>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="选择中心领导">
          <j-select-user-by-dep :multi="false" placeholder="选择中心审批领导" v-decorator="['centerUserName', {}]" :trigger-change="true"></j-select-user-by-dep>
        </a-form-item>
      </a-form>

    </a-spin>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'
import { httpAction, getAction } from '@/api/manage'
import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDep'

export default {
  name: "ChoseApproveModal",
  components: {
    JSelectUserByDep
  },
  data () {
    return {
      title:"选择审批人",
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      username:"",
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules:{
        superiorUserName:{rules: [{ required: false, message: '请输入上级领导用户名!' }]},
      },
      url: {
        submit: "/manage/aeeKpiMain/examine",
      },
    }
  },
  methods: {
    examine (record) {
      this.form.resetFields();
      this.model = Object.assign({}, record);
      this.visible = true;
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(this.model,'centerUserName','superiorUserName'))
      });
    },
    close () {
      this.visible = false;
    },
    handleOk () {
      const that = this;
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
            httpurl+=this.url.submit;
            method = 'post';
          let formData = Object.assign(this.model, values);
          httpAction(httpurl,formData,method).then((res)=>{
            if(res.success){
              that.$message.success(res.message);
              //this.init();
            }else{
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            that.close();
          })



        }
      })
    },
    handleCancel () {
      this.close()
    }
  },


}
</script>

<style scoped>

</style>